package nongchang.kuaijiecaifu.com.ncapp_android.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import ezy.widget.view.AutofitImageView;
import nongchang.kuaijiecaifu.com.ncapp_android.R;
import nongchang.kuaijiecaifu.com.ncapp_android.common.adapter.ItemAdapter;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.good.Cart;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.good.Wholesale;

/**
 * Created by Administrator on 2016/5/4 0004.
 */
public class WholesaleAdapter extends ItemAdapter<Wholesale, WholesaleAdapter.WholesaleViewHolder> {
    private Context context;

    public WholesaleAdapter(Context context) {
        super(context);
        this.context = context;
    }

    private View.OnClickListener onAddNum;  //加商品数量接口
    private View.OnClickListener onSubNum;  //减商品数量接口


    public void setOnAddNum(View.OnClickListener onAddNum) {
        this.onAddNum = onAddNum;
    }


    public void setOnSubNum(View.OnClickListener onSubNum) {
        this.onSubNum = onSubNum;
    }


    @Override
    public WholesaleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new WholesaleViewHolder(inflate(R.layout.item_wholesale, parent));
    }

    @Override
    public void onBindViewHolder(WholesaleViewHolder holder, int position) {
        Wholesale item = getItem(position);
        Glide.with(context).load(item.image).into(holder.imgCart);
        holder.txtTitle.setText(item.title);
        holder.txtOncePrice.setText(item.one_price + "元");
        holder.btnSub.setOnClickListener(onSubNum);
        holder.btnAdd.setOnClickListener(onAddNum);
        holder.txtOriginalPrice.setText(item.original_price + "元");
        holder.btnSub.setTag(position);
        holder.btnAdd.setTag(position);


        holder.editText.setText(item.num + "");

    }

    static class WholesaleViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_cart)
        AutofitImageView imgCart;

        @BindView(R.id.txt_title)
        TextView txtTitle;

        @BindView(R.id.txt_once_price)
        TextView txtOncePrice;


        @BindView(R.id.btn_sub)
        TextView btnSub;

        @BindView(R.id.btn_add)
        TextView btnAdd;

        @BindView(R.id.edit_total)
        EditText editText;

        @BindView(R.id.txt_original_price)
        TextView txtOriginalPrice;

        public WholesaleViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
